home *** CD-ROM | disk | FTP | other *** search
- name network
- page 55,132
- title 'NETBIOS1.SYS --- Netbios Driver'
- ;====================================================================
- ;<M> Module name - network.asm
- ;<A> Abstract - character device driver with interface to Netbios
- ;<C> Copyright (C) 1993 MicroPlot Systems Co., Stephen F. Bean
- ;<C> Released to public Domain October 28, 1993, Stephen F. Bean
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;----
- ERROR equ 8000H
- BUSY equ 0200H
- DONE equ 0100H
- UNKNOWN equ 0003H
- MAX_COMMAND equ 16
- INVALID_COMMAND equ 7fh
- ADD_NAME equ 30h
- DELETE_NAME equ 31h
- NETBIOS_CALL equ 10h
- NETBIOS_LISTEN equ 11h
- NETBIOS_HANG_UP equ 12h
- NETBIOS_SEND equ 14h
- NETBIOS_RECEIVE equ 15h
- SEND_DATAGRAM equ 20h
- RECEIVE_DATAGRAM equ 21h
- SEND_B_DATAGRAM equ 22h
- RCV_B_DATAGRAM equ 23h
- CANCEL_COMMAND equ 35h
- NCB_ADD_GROUP_NAME equ 36h
- NO_WAIT equ 80h
- ;====================================================================
- ;<M> Module name - RequestHeader
- ;<A> Abstract - definition of request header
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;----
- Request struc
- ;
- Rlength db ? ;+0 length of header
- Unit db ? ;+01 unit number
- Command db ? ;+02 command code in header
- Status dw ? ;+03 return status
- Reserve db 8 dup (?) ;+05 reserved area
- Media db ? ;+13 media descriptor
- Address dd ? ;+14 memory address for transfer
- Count dw ? ;+18 byte count
- Sector dw ? ;+20 starting sector
- ;
- Request ends
- ;====================================================================
- ;<M> Module name - InitRequestHeader
- ;<A> Abstract - definition of request header for init call
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;----
- InitRequest struc
- ;
- Rlength db ? ;+0 length of header
- UnitNum db ? ;+01 unit number
- CommCode db ? ;+02 command code in header
- InitStat dw ? ;+03 return status
- ResBytes dq ? ;+05 reserved area
- ;
- InitRequest ends
- ;
- InitHeader struc
- ;
- InitDef db sizeof(InitRequest) dup (?)
- InitUnit db ?
- EndOffset dw ?
- EndSegment dw ?
- ArgOffset dw ? ;current argument in config.sys
- ArgSegment dw ? ;
- ;
- InitHeader ends
- ;====================================================================
- ;<M> Module name - NcbDefinition
- ;<A> Abstract - definition of NETBIOS NCB
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;----
- Ncb struc
- NcbCommand db 00h ;command field
- NcbRetCode db 00h ;return status
- NcbLsn db 00h ;local session number
- NcbNum db 00h ;name number from AddName
- NcbBufferOff dw 0000h ;local buffer offset
- NcbBufferSeg dw 0000h ;local buffer segment
- NcbLength dw 0000h ;buffer length
- NcbCallName db 16 dup (0) ;remote node name
- NcbName db 16 dup (0) ;local name
- NcbRto db 00h ;receive timeout
- NcbSto db 00h ;send timeout
- NcbPostOff dw 0000h ;offset of post routine
- NcbPostSeg dw 0000h ;segment of post routine
- NcbLanaNumber db 00h ;adapter number
- NcbCmdCmplt db 00h ;command pending flag
- NcbReserved db 14 dup (0) ;reserved bytes
- Ncb ends
- ;====================================================================
- ;<M> Module name - DEVICE HEADER
- ;<A> Abstract - at offset 0 within device driver
- ;<D> October 25, 1993
- ;<I> Interface - saves address of request header in local block
- ;<R> Revision Record
- ;<R> 1.
- ;----
- Code segment public 'CODE'
- Driver proc far
- ;
- assume cs:Code, ds:Code, es:Code
- ;
- org 0h ;org for device driver = 0
- ; ;
- dd -1 ;pointer to next header
- dw 1000100000000000B ;attribute-char device, does open/close
- dw Strategy ;pointer to device "strategy" routine
- dw EntryPoint ;pointer to device "interrupt handler"
- DB 'NETBIOS1' ;8 BYTE DEVICE NAME
- ;====================================================================
- ;<M> Module name - local_data
- ;<A> Abstract - local messages & registers
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;----
- ReqPtr dd ? ;pointer to data header
- OutBufferPtr db 0
- InBufferPtr db 0
- InputBuffer db 256 dup (0)
- OutputSize db 'XXXX bytes -'
- MyName db 'xxxx'
- OutputBuffer db 256 dup (0)
- OBuffPtr db 0
- Ident db 13,10,'NETWORK.SYS V1.00'
- db ' (C) 10/25/93 MicroPlot',13,10
- db 'Device Header at '
- DHaddr db 'XXXX:0000'
- db 13,10,0
- NetBiosError db 'NetBios Error # '
- HexValue db 'XXXX',13,10,10,0
- OpenFlag db 0
- NetBiosOpen db 0
- DatagramNcb db sizeof(Ncb) dup (0)
- ReceiveNcb db sizeof(Ncb) dup (0)
- GroupName db 'NETSEND_GROUP',0,0,10
- NameAdd db 'NETSEND_GROUP Name Added',13,10,0
- NameError db 'Error Adding Group Name',13,10,0
- ;====================================================================
- ;<M> Module name - command_table
- ;<A> Abstract - table of functions in device driver
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;----
- CommandTable:
- dw DeviceInitialize ;0
- dw MediaCheck ;1
- dw BuildIopb ;2
- dw IoctlIn ;3
- dw Input ;4
- dw NdInput ;5
- dw InputStat ;6
- dw InputFlush ;7
- dw Output ;8
- dw OutputVerify ;9
- dw OutputStatus ;10
- dw OutputFlush ;11
- dw IoctlOut ;12
- dw DeviceOpen ;13
- dw DeviceClose ;14
- dw RemovableMedia ;15
- dw OutputTillBusy ;16
- ;====================================================================
- ;<M> Module name - Strategy
- ;<A> Abstract - saves address of request header
- ;<D> October 25, 1993
- ;<I> Interface - saves address of request header in local block
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- Strategy proc far
- ;
- mov word ptr cs: [ReqPtr],bx
- mov word ptr cs: [ReqPtr+2],es
- ret
- ;
- Strategy endp
- ;====================================================================
- ;<M> Module name - EntryPoint
- ;<A> Abstract - entry point of the device driver
- ;<A> get here with far call from DOS
- ;<A> save all registers and call routine pointed to in header
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- EntryPoint proc far
- ;
- push ax
- push bx
- push cx
- push dx
- push ds
- push es
- push di
- push si
- push bp
- ;
- push cs
- pop ds ;ds=cs
- ;
- les di,[ReqPtr] ;es:di = request header
- mov bl,es:[di.command] ;get command code
- xor bh,bh ;bh=0
- cmp bx,MAX_COMMAND ;
- jle Intr01 ;
- mov ax,ERROR+UNKNOWN ;set error bit & unknown
- jmp intr02 ;error exit
- ;
- Intr01: shl bx,1 ;word table
- call word ptr [bx+CommandTable]
- les di,[ReqPtr] ;
- Intr02: or ax,DONE ;done bit
- mov es:[di.Status],ax ;
- ;
- pop bp
- pop si
- pop di
- pop es
- pop ds
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- ;
- EntryPoint endp
- ;====================================================================
- ;<M> Module name - DeviceInitialize
- ;<A> Abstract - initialize driver
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- DeviceInitialize proc near
- ;
- push es
- push di
- ;
- mov ax,cs
- mov bx,offset DHaddr
- call HexToAscii
- mov si,offset Ident
- call PrintString
- ;
- pop di
- pop es
- ;
- push es
- push di
- ;
- mov bx,word ptr es:[di.ArgOffset]
- mov ax,word ptr es:[di.ArgSegment]
- mov es,ax
- ;
- FindName: mov al,es:[bx]
- inc bx
- cmp al,' '
- je EndDevName
- jmp FindName
- ;
- ; put name in local register
- ;
- EndDevName: mov cx,4
- mov si,offset MyName
- PutName: mov al,es:[bx]
- mov [si],al
- inc bx
- inc si
- loop PutName
- ;
- pop di
- pop es
- ;
- mov word ptr es:[di.Address],offset ModuleEnd
- mov word ptr es:[di.Address+2],cs
- xor ax,ax
- ret
- ;
- DeviceInitialize endp
- ;====================================================================
- ;<M> Module name - MediaCheck
- ;<A> Abstract - not used on character drivers
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- MediaCheck proc near
- ;
- xor ax,ax
- ret
- ;
- MediaCheck endp
- ;====================================================================
- ;<M> Module name - BuildIopb
- ;<A> Abstract - not used on character drivers
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- BuildIopb proc near
- ;
- xor ax,ax
- ret
- ;
- BuildIopb endp
- ;====================================================================
- ;<M> Module name - IoctlIn
- ;<A> Abstract - IOCTL functions not supported
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- IoctlIn proc near
- ;
- xor ax,ax
- ret
- ;
- IoctlIn endp
- ;====================================================================
- ;<M> Module name - Input
- ;<A> Abstract - transfers data from the device into the specified
- ;<A> memory buffer.
- ;<D> October 25, 1993
- ;<I> Interface - Passed to driver:
- ;<I> Unit Code
- ;<I> Command code = 4
- ;<I> Media Descriptor byte
- ;<I> Transfer address
- ;<I> Byte/Sector Count transferred
- ;<I> Starting sector (block dev. only)
- ;<I> Interface - Returns
- ;<I> Return Status
- ;<I> Actual bytes or sectors transferred
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- Input proc near
- ;
- push es
- push di
- ;
- mov word ptr es:[di.Count],0
- mov al,InBufferPtr
- cmp al,OutBufferPtr
- je NoXfer
- ;
- mov word ptr es:[di.Count],1
- mov bx,word ptr es:[di.Address]
- mov ax,word ptr es:[di.Address+2]
- mov es,ax ;es:bx->buffer
- ;
- mov si,offset InputBuffer
- mov al,OutBufferPtr
- mov ah,0
- add si,ax
- mov al,[si]
- mov es:[bx],al
- inc OutBufferPtr
- ;
- NoXfer: pop es
- pop di
- ;
- xor ax,ax
- ret
- ;
- Input endp
- ;====================================================================
- ;<M> Module name - NdInput
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- NdInput proc near
- ;
- mov al,0
- cmp byte ptr InBufferPtr,0
- je NoNdIn
- mov al,InBufferPtr
- dec al
- mov ah,0
- mov si,offset InputBuffer
- add si,ax
- mov al,[si]
- NoNdIn: mov byte ptr es:[di.Media],al
- xor ax,ax
- ret
- ;
- NdInput endp
- ;====================================================================
- ;<M> Module name - InputStat
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- InputStat proc near
- ;
- xor ax,ax
- ret
- ;
- InputStat endp
- ;====================================================================
- ;<M> Module name - InputFlush
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- InputFlush proc near
- ;
- mov InBufferPtr,0
- xor ax,ax
- ret
- ;
- InputFlush endp
- ;====================================================================
- ;<M> Module name - Output
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - Passed to driver:
- ;<I> Unit Code
- ;<I> Command code = 8
- ;<I> Media Descriptor byte
- ;<I> Transfer address
- ;<I> Byte/Sector Count
- ;<I> Starting sector (block dev. only)
- ;<I> Interface - Returns
- ;<I> Return Status
- ;<I> Actual bytes or sectors transferred
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- Output proc near
- ;
- push es
- push di
- ;
- ; put char in buffer - only send if
- ; char is <cr> or if buffer has 256 bytes
- ;
- push es
- push di
- ;
- mov bx,word ptr es:[di.Address] ;
- mov ax,word ptr es:[di.Address+2] ;
- mov es,ax ;es:bx -> incoming buffer
- mov al,es:[bx] ;get incoming char
- ;
- pop di
- pop es
- ;
- cmp al,0dh ;is <cr>?
- je SendDatagram ;
- cmp al,20h ;printable?
- jl OoXfer ;ignore other control chars
- mov si,offset OutputBuffer ;
- mov cl,OBuffPtr ;
- mov ch,0 ;
- add si,cx ;->next buffer pos
- mov [si],al ;put in buffer
- inc cx ;
- inc OBuffPtr ;
- cmp cx,0fah ;buffer full?
- jl OoXfer ;
- ;
- ; clear out Ncb & put in name
- ;
- SendDatagram: push di
- push es
- mov di,offset DatagramNcb
- call ClearNcb
- mov ax,ds
- mov es,ax
- mov si,offset GroupName
- mov di,offset DatagramNcb.NcbCallName
- mov cx,16
- cld
- rep movsb
- pop es
- pop di
- ;
- ; fill in Ncb
- ;
- mov al,OBuffPtr ;get xfer count
- mov ah,0 ;
- add ax,4 ;add length of host name
- mov DatagramNcb.NcbLength,ax ;put in Ncb
- mov OBuffPtr,0 ;reset pointer
- mov ax,offset MyName ;
- mov DatagramNcb.NcbBufferOff,ax ;offset of data buffer
- mov ax,cs ;
- mov DatagramNcb.NcbBufferSeg,ax ;seg of data buffer
- mov DatagramNcb.NcbNum,1 ;permanent node #
- mov ax,cs ;seg of Ncb
- mov es,ax ;
- mov bx,offset DatagramNcb ;es:bx -> Ncb
- mov DatagramNcb.NcbCommand,SEND_DATAGRAM
- ;
- ; Netbios send datagram
- ;
- int 5ch ;call NETBIOS
- test al,al ;test for error
- jz OoXfer ;
- mov bx,offset HexValue ;
- mov al,DatagramNcb.NcbCmdCmplt ;
- mov ah,0 ;
- call HexToAscii ;
- mov si,offset NetBiosError ;
- call PrintString ;
- ;
- OoXfer: pop es
- pop di
- xor ax,ax
- ret
- ;
- Output endp
- ;
- Idx dw 0
- ;====================================================================
- ;<M> Module name - OutputVerify
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- OutputVerify proc near
- ;
- jmp Output
- ;
- OutputVerify endp
- ;====================================================================
- ;<M> Module name - OutputStatus
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- OutputStatus proc near
- ;
- xor ax,ax
- ret
- ;
- OutputStatus endp
- ;====================================================================
- ;<M> Module name - OutputFlush
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- OutputFlush proc near
- ;
- xor ax,ax
- ret
- ;
- OutputFlush endp
- ;====================================================================
- ;<M> Module name - IoctlOut
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- IoctlOut proc near
- ;
- xor ax,ax
- ret
- ;
- IoctlOut endp
- ;====================================================================
- ;<M> Module name - DeviceOpen
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- DeviceOpen proc near
- ;
- ; check if already open
- ;
- push es
- push di
- ;
- cmp OpenFlag,0
- jne DevOpenErr
- mov OpenFlag,1
- ;
- ; check if Netbios receive is already initialized
- ;
- cmp NetBiosOpen,0
- jne DevOpenExit
- ;
- ; clear Ncb & put in name
- ;
- mov di,offset ReceiveNcb
- call ClearNcb
- mov ax,ds
- mov es,ax
- mov si,offset GroupName
- mov di,offset ReceiveNcb.NcbName
- mov cx,16
- cld
- rep movsb
- ;
- ; add name netbios command
- ;
- mov ReceiveNcb.NcbCommand,NCB_ADD_GROUP_NAME
- mov ax,cs
- mov es,ax
- mov bx,offset ReceiveNcb
- int 5ch
- test al,al
- jnz NetbiosRxErr
- ;
- ; print name add message
- ;
- mov si, offset NameAdd
- call PrintString
- mov NetBiosOpen,1
- call SetupReceive
- ;
- DevOpenExit: pop di
- pop es
- ;
- xor ax,ax
- ret
- ;
- NetbiosRxErr: mov si,offset NameError
- call PrintString
- mov bx,offset HexValue ;
- mov al,ReceiveNcb.NcbCmdCmplt ;
- mov ah,0 ;
- call HexToAscii ;
- mov si,offset NetBiosError ;
- call PrintString ;
- ;
- DevOpenErr: mov ax,ERROR
- pop di
- pop es
- ret
- ;
- DeviceOpen endp
- ;====================================================================
- ;<M> Module name - DeviceClose
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- DeviceClose proc near
- ;
- cmp OpenFlag,1
- jne DevCloErr
- mov OpenFlag,0
- xor ax,ax
- ret
- ;
- DevCloErr: mov ax,ERROR
- ret
- ;
- DeviceClose endp
- ;====================================================================
- ;<M> Module name - RemovableMedia
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- RemovableMedia proc near
- ;
- xor ax,ax
- ret
- ;
- RemovableMedia endp
- ;====================================================================
- ;<M> Module name - OutputTillBusy
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- OutputTillBusy proc near
- ;
- xor ax,ax
- ret
- ;
- OutputTillBusy endp
- ;====================================================================
- ;<M> Module name - SetupReceive
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- SetupReceive proc near
- ;
- push es
- push di
- ;
- mov ReceiveNcb.NcbLength,256
- mov ReceiveNcb.NcbBufferOff,offset InputBuffer
- mov ax,cs
- mov ReceiveNcb.NcbBufferSeg,ax
- mov ReceiveNcb.NcbPostOff,offset ReceivePost
- mov ax,cs
- mov ReceiveNcb.NcbPostSeg,ax
- mov ReceiveNcb.NcbCommand,RECEIVE_DATAGRAM+NO_WAIT
- mov es,ax
- mov bx,offset ReceiveNcb
- int 5ch
- ;
- pop di
- pop es
- ret
- ;
- SetupReceive endp
- ;====================================================================
- ;<M> Module name - ReceivePost
- ;<A> Abstract -
- ;<D> October 25, 1993
- ;<I> Interface - none
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- ReceivePost proc far
- ;
- push ax
- push bx
- push cx
- push dx
- push si
- push di
- push es
- push ds
- sti
- ;
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov si,offset InputBuffer
- mov di,offset MyName
- mov cx,4
- repe cmpsb
- jcxz MyMessage
- ;
- mov si,offset InputBuffer
- mov cx,ReceiveNcb.NcbLength
- mov InBufferPtr,cl
- mov OutbufferPtr,0
- MyMessage: call SetupReceive
- ;
- pop ds
- pop es
- pop di
- pop si
- pop dx
- pop cx
- pop bx
- pop ax ;RESTORE THE WORLD
- iret ;AND RETURN FROM THE POST
- ;
- ReceivePost endp
- ;====================================================================
- ;<M> Module name - HexToAscii
- ;<A> Abstract - converts 16 bit number in AX to 4 digit ASCII
- ;<D> October 25, 1993
- ;<I> Interface - AX = input value
- ;<I> DS:BX = address of string
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- HexToAscii proc near
- ;
- push cx
- push dx
- mov dx,4 ;character counter
- HexAsc1: mov cx,4
- rol ax,cl
- mov cx,ax
- and cx,0fh
- add cx,'0'
- cmp cx,'9'
- jbe HexAsc2
- add cx,'A'-'9'-1
- HexAsc2: mov [bx],cl
- inc bx
- dec dx
- jnz HexAsc1
- pop dx
- pop cx
- ret
- ;
- HexToAscii endp
- ;====================================================================
- ;<M> Module name - PrintString
- ;<A> Abstract - outputs string pointed to by bx
- ;<D> October 25, 1993
- ;<I> Interface - DS:SI = address of string
- ;<R> Revision Record
- ;<R> 1.
- ;====================================================================
- PrintString proc near
- ;
- mov al,[si]
- inc si
- cmp al,0
- je EnPrStr
- mov ah,0eh
- mov bx,0
- push si
- int 10h
- pop si
- jmp PrintString
- EnPrStr: ret
- ;
- PrintString endp
- ;===================================================================
- ;<M> Module name - ClearNcb
- ;<A> Abstract - sets all 64 bytes of Ncb to 0
- ;<D> September 27, 1993
- ;<I> Interface - on entry di-> Ncb to be cleared
- ;<R> Revision Record
- ;<R> 1.
- ;===================================================================
- ClearNcb proc near
- ;
- push cx
- push ax
- push es
- mov ax,ds
- mov es,ax
- mov cx,32
- mov ax,0
- cld
- rep stosw
- pop es
- pop ax
- pop cx
- ret
- ClearNcb endp
- ;
- ModuleEnd dw 0
- ;
- Driver endp
- Code ends
- ;
- end